<template>
	<view>
		<view class="u-p-20">
			<view class="u-flex u-row-between u-col-top">				
				<view class="">
					<view class="u-rela" @click="$u.route('/subcontract/mybag/Subgift/mycode/mycode?type=deposit')">
						<u-image src='https://www.sqkjkj.vip/wxImg/mybag/img3.png' width='308rpx' height='178rpx'></u-image>
					
						<view class="u-abso u-t-0">
							<view class="u-font-20 u-weight u-m-l-30 u-p-t-70">扫码转赠</view>
							<view class="u-font-20 u-m-l-30 u-m-t-20">
								进入<u-icon name='arrow-right' size='20'></u-icon>
							</view>
						</view>
					</view>
				</view>	
				<view class="u-p-b-20 u-font-28 u-text-right u-weight"
					@click="$u.route('/subcontract/mybag/Subgift/massage/massage')">转赠记录</view>
			</view>
				
			<view class=" u-m-t-30 u-weight u-p-l-40" style="border-left: 6rpx solid #FF782C;color: #1C1C1C;">账号转增
			</view>

			<view class="u-m-t-30">
				<u-field v-model="mobile" maxlength="11" @blur="get_member_by_mobile" label="转赠好友" placeholder="请填写手机号">
				</u-field>
			</view>

			<view class="u-m-t-30">
				<u-field v-model="money" label="转赠余额" placeholder="请填余额">
				</u-field>
			</view>
			<view v-if="info.name" class="u-p-20 u-b-r-16 u-flex u-row-between" style="background-color: #F5F5F5;">
				<view class="u-flex">
					<u-image :src="info.avatar" width='78rpx' height='78rpx' shape="circle"></u-image>
					<view class="u-p-l-20">
						<view class="">
							{{info.name}}
						</view>
						<view class="u-font-26 u-m-t-10">
							{{info.mobile}}
						</view>
					</view>
				</view>
			</view>
			<view class="u-m-t-30 u-m-l-20 u-font-28" style="color: #898989;">
				可用余额:<text class="" style="color: #FC3533;">￥{{userinfo.user_wallet}}</text>
			</view>
		</view>
		<!-- 密码弹窗 -->
		<u-popup v-model="show" mode='center'>
			<view class="u-p-30 u-h-200">
				<u-message-input :focus="true" :maxlength='6' @finish="finish"></u-message-input>
			</view>
		</u-popup>
		<!-- @click="$u.route('/pages/my/Recharge/success/success')" -->
		<view class="u-w-650 u-auto u-m-t-50 u-h-100 u-l-h-100 u-text-center u-b-r-13 cl_FFF"
			style="background: linear-gradient(-64deg, #FF382C, #FF633F);"  @click="save">提交</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: "",
				money: '',
				userinfo: '',
				show: false,
				category:1,
				info:'',
				ds:false
			}
		},
		onLoad(o) {
			if(o.category){
				this.category=o.category
			}
			if(o.mobile){
				this.mobile = o.mobile
				this.get_member_by_mobile()
			}
			
		},
		onShow() {
			// 获取我的余额
			this.$api.get_my_massage({}, res => {
				if (res.data.code == 1) {
					this.userinfo = res.data.data.data
					uni.setStorageSync("userinfo", this.userinfo)
				}
			})
		},
		methods: {
			// 点击提交
			save() {
				if (this.mobile == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号'
					})
				} else if (this.money == "") {
					uni.showToast({
						icon: 'none',
						title: '请输入余额'
					})
				}else if (parseFloat(this.money) <=0) {
					uni.showToast({
						icon: 'none',
						title: '转增余额不能为0'
					})
					return
				}else if (parseFloat(this.money) > parseFloat(this.userinfo.user_wallet)) {
					uni.showToast({
						icon: 'none',
						title: '余额不足'
					})
					return
				} else {
					if (uni.getStorageSync('userinfo').have_trade_pwd == 0) {
						uni.showModal({
							title: '提示',
							content: '请先设置余额支付密码',
							success: (res)=> {
								if (res.confirm) {
									this.$u.route('/pages/changePayPassword/changePayPassword')
								} else {
									
								}
							}
						})
						return
					}
					this.show = true
				}
			},
			finish(e) {
				this.show = false
				this.pay(e)
			},
			get_member_by_mobile(){
				if(this.mobile.length==11){
					this.$api.get_member_by_mobile({mobile:this.mobile || ''}, res => {
						if (res.data.code == 1) {
							if(res.data.data.name){
								this.info=res.data.data
							}else{
								uni.showToast({
									title:res.data.msg,
									icon: 'none',
									duration: 2000
								})
								this.info=[]
							}
							
						}
					})
				}
			},
			pay(e) {
				this.$api.my_score_give({
					type: 'deposit',
					category:this.category,
					mobile: this.mobile,
					num: this.money,
					tradepwd: e
				}, res => {
					if (res.data.code == 1) {
						uni.showToast({
							icon: 'none',
							title: "转账成功"
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.one {
		width: 307rpx;
		height: 178rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mybag/img3.png') no-repeat;
		background-size: 100% 100%;
	}

	.one1 {
		width: 307rpx;
		height: 178rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mybag/img2.png') no-repeat;
		background-size: 100% 100%;
	}
</style>
